Skip to content

Comments

【チャレンジ課題】電気料金の情報を返すAPIの作成#69

Open
oyrarumakan wants to merge 6 commits intoenechange:masterfrom
oyrarumakan:feature/create_calc-price-api
Open

【チャレンジ課題】電気料金の情報を返すAPIの作成#69
oyrarumakan wants to merge 6 commits intoenechange:masterfrom
oyrarumakan:feature/create_calc-price-api

Conversation

@oyrarumakan
Copy link

@oyrarumakan oyrarumakan commented Mar 3, 2025

お世話になっております。中村と申します。

ご共有いただいていたチャレンジ課題について実装しましたのでご連絡となります。
お手数ですがご確認いただけますと幸いです。
よろしくお願いいたします。

実装内容

こちらのとおり、与えられたパラメータから電気料金を返却するAPIの実装

具体的な内容

  • ルーティングの新規作成
  • ルーティングに紐づくControllerの新規作成
  • controllerから呼び出すビジネスロジックを管理するhelperの新規作成
  • 料金等を管理するyamlの追加
  • 各種テストの追加

@oyrarumakan oyrarumakan changed the title 電気料金の情報を返すAPIの作成 【チャレンジ課題】電気料金の情報を返すAPIの作成 Mar 3, 2025
@oyrarumakan oyrarumakan marked this pull request as ready for review March 3, 2025 03:44
keys.each do |key|
if usage >= key
unit_price_kwh = thresholds[key]
usage_price = (unit_price_kwh * usage).round(2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000kwhの使用量でAPI実行した場合に、東京電力・従量電灯Bの場合に、電力量料金が 1000kwh * 30.57 になっており、段階的に「使用量 * 単価」の計算がされていないようです。

https://www.tepco.co.jp/ep/private/plan2/chargelist04.html#sec03

errors:
empty_parameter: 'リクエストパラメータにampereとusageを設定してください'
invalid_parameter_type: 'ampereとusageはいずれも数値を設定してください'
invalid_contract_ampere: 'ampereの値が正しくありません'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

どのような値を設定すれば正しいのか判別できるエラーメッセージだと親切かと思いました。

end

# yamlからパラメータ読み込み
def import_price_from_yaml(ampere, usage)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import_price_from_yaml関数が、ymlからデータを読み込む以上の処理をしています。

関数内の処理を別関数に切り出すなどした方が保守性・可読性は上がると思いましたが、いかがでしょうか。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants